<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'  @exportHandler='exportDate'  :show-export-btn='true'>
      <f-search-form-item label='账套' name='companyId' type='select' valueKey='companyId' labelKey='companyName' :params='{accountName: this.$store.state.user.userName}' :data='this.api.company.getAccount' />
      <f-search-form-item label='单位名称' name='customName' />
      <f-search-form-item label='开始日期' type='range' name='beginDate' />
      <f-search-form-item label='订单编号' name='orderNo' slot='advanced'/>
      <f-search-form-item label='部门' ref='dept' name='deptId' type='select' :data='api.hyorder.listByCompanyId' valueKey='deptId' label-key='deptName' slot='advanced'/>
    </f-search-form>
    <f-table ref='table' rowKey='orderId' :columns='columns'
             :scroll='{x:true}' :multiple='false' 
             :operator='operator' :params='queryParam'
             :api='api.hyorder' handler='hySearchOrderTab1ListHandler'>
        <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
            <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
            <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
            <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
        </span>
      <span slot='invoiceType' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==1'>普票</a-tag>
            <a-tag color='purple' v-if='text==2'>专票</a-tag>
        </span>
      <span slot='sendState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未发货</a-tag>
            <a-tag color='purple' v-if='text==1'>已提单</a-tag>
        </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click='$refs.orderInvoiceDrawer.showDrawer(record)'>详情</a>
             <a-divider type='vertical' />
             <a href='javascript:;' @click='$refs.fastMailDrawer.showDrawer(record)' v-if='!record.invoiceFastMailNo'>发票物流</a>
               <a-divider type='vertical' v-if='!record.invoiceFastMailNo'/>
             <a-dropdown>
            <a class='ant-dropdown-link'>更多<a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item>
                <a href='javascript:;' @click='$refs.gxhtModal.open(record)'>下载购销合同</a>
              </a-menu-item>
              <a-menu-item v-if='record.invoiceFastMailNo'>
                <a href='javascript:;' @click='$refs.fastMailDrawer.showDrawer(record)' >发票物流</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
          </template>
        </span>
    </f-table>
    <order-search-drawer ref='orderInvoiceDrawer'></order-search-drawer>
    <gxht-modal ref='gxhtModal'></gxht-modal>
    <fast-mail-drawer ref='fastMailDrawer'></fast-mail-drawer>
  </div>
</template>
<script>
import api from "../../js/api"
import OrderSearchDrawer from "./components/order_search_drawer"
import GxhtModal from "@/views/module/haiying/order/components/gxht_modal"
import FastMailDrawer from "@/views/module/haiying/order/search/components/fastmail_drawer"

export default {
  name: "Tab3",
  components: {
    FastMailDrawer,
    GxhtModal,
    OrderSearchDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      activeKey: "0",
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "账套",
          align: "left",
          width: "110px",
          dataIndex: "companyName"
        },
        {
          title: "订单编号",
          align: "left",
          width: "120px",
          dataIndex: "orderNo"
        },
        {
          title: "出库单号",
          align: "left",
          width: "120px",
          dataIndex: "outOrderNo"
        },
        {
          title: "单据日期",
          align: "left",
          width: "120px",
          dataIndex: "sendDate"
        },
        {
          title: "部门",
          align: "left",
          dataIndex: "deptName"
        },
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "130px",
          dataIndex: "customName"
        },
        {
          title: "业务员",
          align: "left",
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          dataIndex: "businessCode"
        },
        {
          title: "发货方式",
          align: "center",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "提单状态",
          align: "center",
          dataIndex: "sendState",
          scopedSlots: { customRender: "sendState" }
        },

        {
          title: "发货物流公司",
          align: "left",
          width: "110px",
          dataIndex: "fastMailName"
        },
        {
          title: "发货物流单号",
          align: "left",
          width: "110px",
          dataIndex: "fastMailNo"
        },
        {
          title: "发票类型",
          align: "left",
          dataIndex: "invoiceType",
          scopedSlots: { customRender: "invoiceType" }
        },
        {
          title: "开票要求",
          align: "left",
          ellipsis: true,
          dataIndex: "invoiceRemark"
        },
        {
          title: "发票号码",
          align: "left",
          width: "110px",
          dataIndex: "invoiceNo"
        },
        {
          title: "发票日期",
          align: "left",
          width: "110px",
          dataIndex: "invoiceDate"
        },
        {
          title: "发票物流公司",
          align: "left",
          width: "110px",
          dataIndex: "invoiceFastMailName"
        },
        {
          title: "发票物流单号",
          align: "left",
          width: "110px",
          dataIndex: "invoiceFastMailNo"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "180px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator,
      processImageVisible: false,
      processInstanceId: null
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    //申请撤销开票
    cancelInvoiceInfo(order) {
      this.http.confirm(this, {
        content: "确认取消开票申请吗?",
        url: api.hyorder.cancelInvoiceInfo,
        data: {
          orderId: order.orderId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    changeHandler(activeKey) {
      this.activeKey = activeKey
      this.$refs.table.refresh(true, { activeKey: this.activeKey })
    },
    exportDate(url,searchParams){
      this.$message.loading("数据导出中..", 0)
      this.http.exportExcel(this, {
        url: this.api.hyOrderDetails.exportTemplate,
        data: {
          fileName: "物流对账表-",
          ...searchParams,
          handlerName: "hySearchExportListHandler",
        }
      })
    },
    processImg(order) {
      this.processInstanceId = order.processInstanceId
      this.processImageVisible = true
    }
  }
}
</script>
